package com.android.widget.horizontalscrollview;

import java.util.Map;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;


public class HorizontalScrollViewWidget extends LinearLayout {
    
    private Context mContext;
    public HorizontalScrollViewWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context; 
    }

    
    public void setAdapter(HorizontalScrollViewAdapter adapter) {
        for(int i=0;i<adapter.getCount();i++){
            final Map<String,Object> map=(Map<String, Object>) adapter.getItem(i);
            View view=adapter.getView(i, null, null);
            view.setPadding(10, 0, 10, 0); 
            view.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(mContext, "this is a toast."+map.get("text"), Toast.LENGTH_SHORT).show();
                }   
            }); 
            this.setOrientation(HORIZONTAL);
            this.addView(view,new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
        }   
    } 
    
    public void setAdapter(HorizontalScrollViewAdapter2 adapter) {
        for(int i=0;i<adapter.getCount();i++){
            final Map<String,Object> map=(Map<String, Object>) adapter.getItem(i);
            View view=adapter.getView(i, null, null);
            view.setPadding(150, 0, 150, 0); 
            view.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(mContext, "this is a toast."+map.get("text"), Toast.LENGTH_SHORT).show();
                }   
            }); 
            this.setOrientation(HORIZONTAL);
            this.addView(view,new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
        }   
    }     

}
